package org.example.controller;


import org.example.bean.Supplier;
import org.example.service.Impl.SupplierServise;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class SupplierController {
    @Autowired
    SupplierServise supplierServise;
    @RequestMapping("/Supplierlist.do")
    @ResponseBody   //1、修饰当前方法返回类型为JSON
    public List<Supplier> getAll(){  //2、将需要转换成json格式的对象直接返回
        List<Supplier> list =  supplierServise.getAll();
        System.out.println("打印SUP表");
        return list;
    }
    @RequestMapping("/delete1.do")
    public void delete(int id){
        supplierServise.del(id);
    }
    @RequestMapping("/add1.do")
    public String add(@RequestParam("name") String name,@RequestParam("uname") String uname,@RequestParam("tel") long tel
    ,@RequestParam("mail") String mail,@RequestParam("text") String text){
        Supplier supplier=new Supplier();
        supplier.setName(name);
        supplier.setTel(tel);
        supplier.setUname(uname);
        supplier.setMail(mail);
        supplier.setText(text);
        supplierServise.add(supplier);
        return"供应商管理";
    }
    @RequestMapping("/update2.do")
    public String update(@RequestParam("id")int id,@RequestParam("name") String name,@RequestParam("uname") String uname,@RequestParam("tel") long tel
            ,@RequestParam("mail") String mail,@RequestParam("text") String text){
        Supplier supplier=new Supplier();
        supplier.setId(id);
        supplier.setName(name);
        supplier.setTel(tel);
        supplier.setUname(uname);
        supplier.setMail(mail);
        supplier.setText(text);
        supplierServise.update(supplier);
        System.out.println("dasdsa");
        return"供应商管理";
    }

}
